/*
 * Copyright 2009 Aleksandar Seovic
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.seovic.validation;

import java.io.Serializable;
import java.util.Locale;

/**
 * Represents a single validation error message.
 *
 * @author as  2005.11.13
 * @author ic  2009.06.04
 */
public class ErrorMessage implements Serializable {
	private static final long serialVersionUID = 2282118723209679515L;


    // ---- data members ----------------------------------------------------

	private String   id;
    private Object[] parameters;


    // ---- constructors ----------------------------------------------------

    /**
     * Default constructor.
     */
    public ErrorMessage() {}

    /**
     * Initializes a new instance of the ErrorMessage class.
     *
     * @param id          Error message resource identifier.
     * @param parameters  Parameters that should be used for message resolution.
     */
    public ErrorMessage(String id, Object[] parameters) {
        this.id         = id;
        this.parameters = parameters;
    }


    // ---- getters and setters ---------------------------------------------

    /**
     * Gets or sets the resource identifier for this message.
     *
     * @return The resource identifier for this message.
     */
    public String getId() {
    	return id;
    }

    /**
     * Gets or sets the message parameters.
     * 
     * @return The message parameters.
     */
    public Object[] getParameters() {
    	return parameters;
    }


    // ---- ErrorMessage public methods -------------------------------------
    
    public String getMessage(MessageSource messageSource) {
        return messageSource.getMessage(id, parameters, Locale.getDefault());
    }
}